
import { defineConfig, loadEnv } from "vite";
import path from "path";
import { createVitePlugins } from "./vite/plugins/index";
import { useModeEnv } from "./vite/utls/use-mode-env";
import { createProxy } from "./vite/utls/create-proxy";


export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd(), "");
    const { isProd, getEnvConfig } = useModeEnv(mode, env);
    const envConfig = getEnvConfig();

    return {
        base: "/",
        plugins: createVitePlugins(isProd),
        resolve: {
            alias: { "@": path.resolve(process.cwd(), "src") },
        },

        server: {
            host: "localhost",
            open: true,
            port: parseInt(envConfig.VITE_PORT),
            proxy: createProxy(env),
        },
        css: {
            preprocessorOptions: {
                less: {
                    math: "parens-division",
                },
            },
        },
    };
});
